<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The MongoDB\Driver\Cursor class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongodb-driver-readconcern.unserialize.html">« MongoDB\Driver\ReadConcern::unserialize</a></li>
      <li style="float: right;"><a href="mongodb-driver-cursor.construct.html">MongoDB\Driver\Cursor::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.mongodb.html">MongoDB\Driver</a></li>
    <li>The MongoDB\Driver\Cursor class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.mongodb-driver-cursor" class="reference">

 <h1 class="title">The MongoDB\Driver\Cursor class</h1>
 

 <div class="partintro"><p class="verinfo">(mongodb &gt;=1.0.0)</p>


  <div class="section" id="mongodb-driver-cursor.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    The <span class="classname"><strong class="classname">MongoDB\Driver\Cursor</strong></span> class encapsulates
    the results of a MongoDB command or query and may be returned by
    <span class="methodname"><a href="mongodb-driver-manager.executecommand.html" class="methodname">MongoDB\Driver\Manager::executeCommand()</a></span> or
    <span class="methodname"><a href="mongodb-driver-manager.executequery.html" class="methodname">MongoDB\Driver\Manager::executeQuery()</a></span>, respectively.
   </p>
  </div>


  <div class="section" id="mongodb-driver-cursor.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="modifier">final</span>
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">MongoDB\Driver\Cursor</strong>
     </span>

     <span class="oointerface"><span class="modifier">implements</span> 
       <strong class="interfacename">MongoDB\Driver\CursorInterface</strong></span><span class="oointerface">,  <a href="class.iterator.html" class="interfacename">Iterator</a></span> {</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">private</span> <span class="methodname"><a href="mongodb-driver-cursor.construct.html" class="methodname">__construct</a></span>()</div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-cursor.current.html" class="methodname">current</a></span>(): <span class="type"><span class="type">array</span>|<span class="type">object</span>|<span class="type">null</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-cursor.getid.html" class="methodname">getId</a></span>(): <span class="type"><a href="class.mongodb-driver-cursorid.html" class="type MongoDB\Driver\CursorId">MongoDB\Driver\CursorId</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-cursor.getserver.html" class="methodname">getServer</a></span>(): <span class="type"><a href="class.mongodb-driver-server.html" class="type MongoDB\Driver\Server">MongoDB\Driver\Server</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-cursor.isdead.html" class="methodname">isDead</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-cursor.key.html" class="methodname">key</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-cursor.next.html" class="methodname">next</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-cursor.rewind.html" class="methodname">rewind</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-cursor.settypemap.html" class="methodname">setTypeMap</a></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$typemap</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-cursor.toarray.html" class="methodname">toArray</a></span>(): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-cursor.valid.html" class="methodname">valid</a></span>(): <span class="type">bool</span></div>

   }</div>


  </div>

  <div class="section">
   <h2 class="title">更新日志</h2>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>版本</th>
        <th>说明</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>PECL mongodb 1.9.0</td>
        <td>
         Implements <span class="interfacename"><a href="class.iterator.html" class="interfacename">Iterator</a></span>.
        </td>
       </tr>

       <tr>
        <td>PECL mongodb 1.6.0</td>
        <td>
         Implements <span class="interfacename"><strong class="interfacename">MongoDB\Driver\CursorInterface</strong></span>,
         which extends <span class="interfacename"><a href="class.traversable.html" class="interfacename">Traversable</a></span>.
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
  </div>

  <div class="section" id="mongodb-driver-cursor.examples">
   <h2 class="title">范例</h2>

   <div class="example" id="mongodb-driver-cursor.examples.foreach">
    <p><strong>示例 #1 Reading a result set</strong></p>
    <div class="example-contents"><p>
     <span class="methodname"><a href="mongodb-driver-manager.executecommand.html" class="methodname">MongoDB\Driver\Manager::executeCommand()</a></span> and
     <span class="methodname"><a href="mongodb-driver-manager.executequery.html" class="methodname">MongoDB\Driver\Manager::executeQuery()</a></span> both return
     their result(s) as a <span class="classname"><strong class="classname">MongoDB\Driver\Cursor</strong></span> object.
     This object can be used to iterate over the result set of the command or
     query.
    </p></div>
    <div class="example-contents"><p>
     Because <span class="classname"><strong class="classname">MongoDB\Driver\Cursor</strong></span> implements the
     <span class="interfacename"><a href="class.traversable.html" class="interfacename">Traversable</a></span> interface, you can simply
     iterate over the result set with
     <a href="control-structures.foreach.html" class="link"><code class="literal">foreach</code></a>.
    </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;Insert&nbsp;some&nbsp;documents&nbsp;so&nbsp;that&nbsp;our&nbsp;query&nbsp;returns&nbsp;information&nbsp;*/<br /></span><span style="color: #0000BB">$bulkWrite&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">BulkWrite</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bulkWrite</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">([</span><span style="color: #DD0000">'name'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Ceres'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'size'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">946</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'distance'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">2.766</span><span style="color: #007700">]);<br /></span><span style="color: #0000BB">$bulkWrite</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">([</span><span style="color: #DD0000">'name'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Vesta'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'size'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">525</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'distance'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">2.362</span><span style="color: #007700">]);<br /></span><span style="color: #0000BB">$manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeBulkWrite</span><span style="color: #007700">(</span><span style="color: #DD0000">"test.asteroids"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bulkWrite</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Query&nbsp;for&nbsp;all&nbsp;the&nbsp;items&nbsp;in&nbsp;the&nbsp;collection&nbsp;*/<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Query</span><span style="color: #007700">(&nbsp;[]&nbsp;);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Query&nbsp;the&nbsp;"asteroids"&nbsp;collection&nbsp;of&nbsp;the&nbsp;"test"&nbsp;database&nbsp;*/<br /></span><span style="color: #0000BB">$cursor&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">"test.asteroids"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;$cursor&nbsp;now&nbsp;contains&nbsp;an&nbsp;object&nbsp;that&nbsp;wraps&nbsp;around&nbsp;the&nbsp;result&nbsp;set.&nbsp;Use<br />&nbsp;*&nbsp;foreach()&nbsp;to&nbsp;iterate&nbsp;over&nbsp;all&nbsp;the&nbsp;result&nbsp;*/<br /></span><span style="color: #007700">foreach(</span><span style="color: #0000BB">$cursor&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$document</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$document</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
stdClass Object
(
    [_id] =&gt; MongoDB\BSON\ObjectId Object
        (
            [oid] =&gt; 5a4cff2f122d3321565d8cc2
        )

    [name] =&gt; Ceres
    [size] =&gt; 946
    [distance] =&gt; 2.766
)
stdClass Object
(
    [_id] =&gt; MongoDB\BSON\ObjectId Object
        (
            [oid] =&gt; 5a4cff2f122d3321565d8cc3
        )

    [name] =&gt; Vesta
    [size] =&gt; 525
    [distance] =&gt; 2.362
}
</pre></div>
    </div>
   </div>

   <div class="example" id="mongodb-driver-cursor.examples.tailable">
    <p><strong>示例 #2 Reading a result set for a tailable cursor</strong></p>
    <div class="example-contents"><p>
     <a href="https://www.mongodb.com/docs/manual/core/tailable-cursors" class="link external">&raquo;&nbsp;Tailable cursors</a>
     are a special type of MongoDB cursor that allows the client to read some
     results and then wait until more documents become available. These cursors
     are primarily used with
     <a href="https://www.mongodb.com/docs/manual/core/capped-collections" class="link external">&raquo;&nbsp;Capped Collections</a>
     and <a href="https://www.mongodb.com/docs/manual/changeStreams" class="link external">&raquo;&nbsp;Change Streams</a>.
    </p></div>
    <div class="example-contents"><p>
     While normal cursors can be iterated once with <code class="literal">foreach</code>,
     that approach will not work with tailable cursors. When
     <code class="literal">foreach</code> is used with a tailable cursor, the loop will
     stop upon reaching the end of the initial result set. Attempting to
     continue iteration on the cursor with a second
     <code class="literal">foreach</code> would throw an exception, since PHP attempts to
     rewind the cursor. Similar to result objects in other database drivers,
     cursors in MongoDB only support forward iteration, which means they cannot
     be rewound.
    </p></div>
    <div class="example-contents"><p>
     In order to continuously read from a tailable cursor, the Cursor object
     must be wrapped with an <span class="classname"><a href="class.iteratoriterator.html" class="classname">IteratorIterator</a></span>. This
     allows the application to directly control the cursor&#039;s iteration, avoid
     inadvertently rewinding the cursor, and decide when to wait for new results
     or stop iteration entirely.
    </p></div>
    <div class="example-contents"><p>
     In order to demonstrate a tailable cursor in action, two scripts will be
     used: a &quot;producer&quot; and a &quot;consumer&quot;. The producer script will create a new
     capped collection using the
     <a href="https://www.mongodb.com/docs/manual/reference/command/create" class="link external">&raquo;&nbsp;create</a> command
     and proceed to insert a new document into that collection each second.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeCommand</span><span style="color: #007700">(</span><span style="color: #DD0000">'test'</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Command</span><span style="color: #007700">([<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'create'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'asteroids'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'capped'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'size'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1048576</span><span style="color: #007700">,<br />]));<br /><br />while&nbsp;(</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bulkWrite&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">BulkWrite</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bulkWrite</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">([</span><span style="color: #DD0000">'createdAt'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">BSON</span><span style="color: #007700">\</span><span style="color: #0000BB">UTCDateTime</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeBulkWrite</span><span style="color: #007700">(</span><span style="color: #DD0000">'test.asteroids'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bulkWrite</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     With the producer script still running, a second consumer script may be
     executed to read the inserted documents using a tailable cursor, indicated
     by the <code class="literal">tailable</code> and <code class="literal">awaitData</code> options
     to <span class="function"><a href="mongodb-driver-query.construct.html" class="function">MongoDB\Driver\Query::__construct()</a></span>.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Query</span><span style="color: #007700">([],&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'tailable'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'awaitData'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,<br />]);<br /><br /></span><span style="color: #0000BB">$cursor&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">'test.asteroids'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$iterator&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">IteratorIterator</span><span style="color: #007700">(</span><span style="color: #0000BB">$cursor</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$iterator</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">rewind</span><span style="color: #007700">();<br /><br />while&nbsp;(</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$iterator</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">valid</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$document&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$iterator</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">current</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Consumed&nbsp;document&nbsp;created&nbsp;at:&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$document</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createdAt</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$iterator</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">next</span><span style="color: #007700">();<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     The consumer script will start by quickly printing all available documents
     in the capped collection (as if <code class="literal">foreach</code> had been used);
     however, it will not terminate upon reaching the end of the initial result
     set. Since the cursor is tailable, calling
     <span class="function"><a href="iteratoriterator.next.html" class="function">IteratorIterator::next()</a></span> will block and wait for
     additional results. <span class="function"><a href="iteratoriterator.valid.html" class="function">IteratorIterator::valid()</a></span> is also
     used to check if there is actually data available to read at each step.
    </p></div>
    <blockquote class="note"><p><strong class="note">注意</strong>: 
     <span class="simpara">
      This example uses the <code class="literal">awaitData</code> query option to
      instruct the server to block for a short period (e.g. one second) at the
      end of the result set before returning a response to the driver. This is
      used to prevent the driver from aggressively polling the server when there
      are no results available. The <code class="literal">maxAwaitTimeMS</code> option may
      be used in conjunction with <code class="literal">tailable</code> and
      <code class="literal">awaitData</code> to specify the amount of time that the server
      should block when it reaches the end of the result set.
     </span>
    </p></blockquote>
   </div>
  </div>

  <div class="section">
   <h2 class="title">错误／异常</h2>
   <p class="simpara">
    When iterating over the cursor object, BSON data is converted into PHP
    variables. This iteration can cause the following Exceptions:
   </p>
   <ul class="simplelist">
    <li class="member">
     Throws
     <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> if
     a class in the type map cannot be instantiated or does not implement
     <span class="interfacename"><a href="class.mongodb-bson-unserializable.html" class="interfacename">MongoDB\BSON\Unserializable</a></span>.
    </li>
    <li class="member">Throws <span class="classname"><a href="class.mongodb-driver-exception-unexpectedvalueexception.html" class="classname">MongoDB\Driver\Exception\UnexpectedValueException</a></span> if the input did not contain exactly one BSON document. Possible reasons include, but are not limited to, invalid BSON, extra data (after reading one BSON document), or an unexpected <a href="https://github.com/mongodb/mongo-c-driver/tree/master/src/libbson" class="link external">&raquo;&nbsp;libbson</a> error.</li>
   </ul>
  </div>

 </div>

 
 












 













 









 





 





 


 






 









 



<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="mongodb-driver-cursor.construct.html">MongoDB\Driver\Cursor::__construct</a> — Create a new Cursor (not used)</li><li><a href="mongodb-driver-cursor.current.html">MongoDB\Driver\Cursor::current</a> — Returns the current element</li><li><a href="mongodb-driver-cursor.getid.html">MongoDB\Driver\Cursor::getId</a> — Returns the ID for this cursor</li><li><a href="mongodb-driver-cursor.getserver.html">MongoDB\Driver\Cursor::getServer</a> — Returns the server associated with this cursor</li><li><a href="mongodb-driver-cursor.isdead.html">MongoDB\Driver\Cursor::isDead</a> — Checks if the cursor is exhausted or may have additional results</li><li><a href="mongodb-driver-cursor.key.html">MongoDB\Driver\Cursor::key</a> — Returns the current result's index within the cursor</li><li><a href="mongodb-driver-cursor.next.html">MongoDB\Driver\Cursor::next</a> — Advances the cursor to the next result</li><li><a href="mongodb-driver-cursor.rewind.html">MongoDB\Driver\Cursor::rewind</a> — Rewind the cursor to the first result</li><li><a href="mongodb-driver-cursor.settypemap.html">MongoDB\Driver\Cursor::setTypeMap</a> — Sets a type map to use for BSON unserialization</li><li><a href="mongodb-driver-cursor.toarray.html">MongoDB\Driver\Cursor::toArray</a> — Returns an array containing all results for this cursor</li><li><a href="mongodb-driver-cursor.valid.html">MongoDB\Driver\Cursor::valid</a> — Checks if the current position in the cursor is valid</li></ul>
</div>
</div></div></body></html>